package com.ruoyi.aipic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.aipic.domain.Genpic;
import com.ruoyi.aipic.service.IGenpicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片生成Controller
 * 
 * @author ruoyi
 * @date 2024-11-02
 */
@RestController
@RequestMapping("/aipic/genpic")
public class GenpicController extends BaseController
{
    @Autowired
    private IGenpicService genpicService;

    /**
     * 查询图片生成列表
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:list')")
    @GetMapping("/list")
    @DataScope(userAlias = "u")
    public TableDataInfo list(Genpic genpic)
    {
        startPage();
        List<Genpic> list = genpicService.selectGenpicList(genpic);
        return getDataTable(list);
    }

    /**
     * 导出图片生成列表
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:export')")
    @Log(title = "图片生成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Genpic genpic)
    {
        List<Genpic> list = genpicService.selectGenpicList(genpic);
        ExcelUtil<Genpic> util = new ExcelUtil<Genpic>(Genpic.class);
        util.exportExcel(response, list, "图片生成数据");
    }

    /**
     * 获取图片生成详细信息
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(genpicService.selectGenpicById(id));
    }

    /**
     * 新增图片生成
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:add')")
    @Log(title = "图片生成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Genpic genpic)
    {
        return toAjax(genpicService.insertGenpic(genpic));
    }

    /**
     * 修改图片生成
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:edit')")
    @Log(title = "图片生成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Genpic genpic)
    {
        return toAjax(genpicService.updateGenpic(genpic));
    }

    /**
     * 删除图片生成
     */
    @PreAuthorize("@ss.hasPermi('aipic:genpic:remove')")
    @Log(title = "图片生成", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(genpicService.deleteGenpicByIds(ids));
    }
}
